<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var time1 = setInterval(function() {
        //     console.log('2秒过去了。。。');
        // }, 2000)

        // clearInterval(time1)// 清除定时器

        // 敌军还有30秒到达战场，碾碎他们！
        var time = 5;
        var timer = setInterval(function() {
            if(time === 0) {
                clearInterval(timer)
            }
            console.log('敌军还有'+(time--)+'秒到达战场，碾碎他们！');
        }, 1000)
    </script>
</body>
</html>